// ignore_for_file: non_constant_identifier_names

import 'package:flutter/material.dart';
import 'package:flutter_lui/flutter_lui.dart';

class LNavigatorObserver extends NavigatorObserver {
  /// 系统事件 跳转到新页面
  ///
  /// 事件监听器: [Route\<dynamic\> 新路由对象, Route\<dynamic\>?   上一个路由对象]
  static String ROUTE_DID_PUSH = 'route_did_push';

  /// 系统事件 替换旧页面跳转到新页面
  ///
  /// 事件监听器: [Route\<dynamic\>? 新路由对象, Route\<dynamic\>?  旧路由对象]
  static String ROUTE_DID_REPLACE = 'route_did_replace';

  /// 系统事件 页面删除
  ///
  /// 事件监听器: [Route\<dynamic\> 删除的路由对象, Route\<dynamic\>?  上一个路由对象]
  static String ROUTE_DID_REMOVE = 'route_did_remove';

  /// 系统事件 页面后退
  ///
  /// 事件监听器: [Route\<dynamic\> 从此路由对象后退, Route\<dynamic\>?  退回到此路由对象]
  static String ROUTE_DID_POP = 'route_did_pop';

  /// 系统事件 路由变化
  ///
  ///  事件监听器: [Route\<dynamic\> 当前路由对象, Route\<dynamic\>?  隐藏的路由对象]
  static String ROUTE_DID_UPDATE = 'route_did_update';

  /// 当前页面的路由对象
  static Route<dynamic>? currentRoute;

  @override
  void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
    currentRoute = route;
    LEvents.instance.send(ROUTE_DID_PUSH, [route, previousRoute]);
    LEvents.instance.send(ROUTE_DID_UPDATE, [route, previousRoute]);
  }

  @override
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
    currentRoute = newRoute;
    LEvents.instance.send(ROUTE_DID_REPLACE, [newRoute, oldRoute]);
    LEvents.instance.send(ROUTE_DID_UPDATE, [newRoute, oldRoute]);
  }

  @override
  void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
    currentRoute = previousRoute;
    LEvents.instance.send(ROUTE_DID_REMOVE, [route, previousRoute]);
    LEvents.instance.send(ROUTE_DID_UPDATE, [previousRoute, route]);
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
    currentRoute = previousRoute;
    LEvents.instance.send(ROUTE_DID_POP, [route, previousRoute]);
    LEvents.instance.send(ROUTE_DID_UPDATE, [previousRoute, route]);
  }
}
